﻿using Messhall.Domain.Permission.BusinessObjects;
using Messhall.Framework.Repository.Repositorys;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Messhall.Repository.Permission.EntityTypeConfigurations
{
    public class PermissionEntityConfiguration : EntityTypeConfigurationBase<
        Messhall.Domain.Permission.BusinessObjects.PermissionEntity>
    {
        public override void Configure(
            EntityTypeBuilder<Messhall.Domain.Permission.BusinessObjects.PermissionEntity> builder)
        {
            builder.ToTable("permissions");
            builder.Property(c => c.Name).HasMaxLength(200).IsRequired();
            builder.Property(c => c.Code).HasMaxLength(20).IsRequired();
            builder.Property(c => c.Icon).HasMaxLength(50).HasDefaultValue(string.Empty).IsRequired();
            builder.Property(c => c.Remark).HasMaxLength(255).IsRequired();
            builder.Property(c => c.Uri).HasMaxLength(255).IsRequired();
            builder.Property(c => c.ParentId).IsRequired();
            builder.HasMany(c => c.PermissionCodes).WithOne(c => c.Permission).HasForeignKey(c => c.PermissionKeyId);

            base.Configure(builder);
        }
    }
}